package process;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;

public class SendFileUDP {
//	private String m_host = "10.0.2.2";
	private int i_port = 8080;
	
//	private String m_Path = "/sdcard";
	//private String m_filename = "b.ppt";
	private int size = 1400;
	private String m_Start = "SendFileName";
	private String m_Content = "SendContenFile";
	private String m_End = "Kết thúc";
	private InputStream is;
	private FileInputStream fis;
	private BufferedInputStream bis;
	
	
	public String SendUsingUDP(String m_Path ,String m_filename,String m_host)
	{
		String thongbao ="";
		SendAllFile send = new SendAllFile();
		int kq = send.SendInfoStartSendUDP(m_host, i_port, m_Start);
		
	//	int kq3 = send.sendInfoEndSend(m_host, i_port, m_End);
		if(kq==1)
		{
			
			//int ip = Integer.parseInt(m_host);
			//ServerSocket serverSocket;
			/*String line = "";
			try {
			 DatagramSocket serverSocket = new DatagramSocket(i_port);
				byte[] receiveData = new byte[1024];
				DatagramPacket receivePacket = new DatagramPacket(receiveData,receiveData.length);
				serverSocket.receive(receivePacket);

				//serverSocket = new ServerSocket(i_port);
				//Socket client = serverSocket.;
				line = new String(receivePacket.getData());
				// BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
		       // line=in.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 if(line.equals("OK"))
			 {
		*/
			
				//int kq1 = send.SendfilenameUDP(m_host, i_port, m_filename);
				/*try {
					//Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				if(kq!=0)
				{
				//	int kq2 = send.SendfilenameUDP(m_host, i_port, m_Content);
					int kq3 = send.SenContentFileUDP(m_Path, m_filename, m_host, i_port);
					thongbao = "successful"+kq3;
					
				}
				else
				{
					thongbao = "unsuccessful";
				}
			 }
		//}
		
		
		return thongbao;
		
		
	}

}
